using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Controller;
using Cliente.Objetos;
using Cliente.Forms;


namespace Cliente
{
    public partial class TelaLogin : Form
    {
        public bool Authenticated;

        public TelaLogin()
        {
            InitializeComponent();
        }

        private void linkClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            loginWorker.RunWorkerAsync();
        }

        private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressLogin.Text = (string)e.UserState;
            progressLogin.Refresh();
        }

        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            loginWorker.ReportProgress(1, "Carregando...");
            Authenticated = Controller.Usuario.AutenticarUsuario(this.tbxLogin.Text  , this.tbxSenha.Text  );
        }

        private void Authenticate(string userName, string password)
        {
        }

        private void tbxSenha_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) button1_Click(sender, e);
        }

        private void tbxLogin_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) button1_Click(sender, e);
        }

        private void loginWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (Authenticated)
            {
                App.strLogin = tbxLogin.Text;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("Acesso negado");
            }

        }


    }
}